<?php

namespace AppBundle\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use AppBundle\Util\Crypt\CryptUtil;

/**
 * Description of EncryptCommand
 *
 * @author yihao
 */
class EncryptCommand extends Command
{
    
    protected function configure()
    {
        $this
                ->setName('app:encrypt')
                ->setDescription('Encrypt plain text.')
                ->setDefinition(array(
                    new InputArgument('msg', InputArgument::REQUIRED, 'The plain text to encrypt'),
                ))
                ->setHelp(<<<EOT
The <info>app:encrypt</info> command encrypt a plain text.

You must alternatively specify the msg to encrypt as the first argument:

  <info>php bin/console app:encrypt msg</info>

EOT
                );
    }
    
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $msg = $input->getArgument('msg');
        
        $result = CryptUtil::encrypt($msg);
        
        $output->writeln('Encrypt result: ' . $result);
    }
    
}
